﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace DnD.Model
{
    [Table]
    class CardAction
    {

  private int _id;
        private EntityRef<DnDAction> _actionRef;
        private EntityRef<Card> _cardRef;
        private bool _local;

        private int _actionID;
        private int _cardID;

        [Column]
        public int CardID {  get {return _cardID;}
            set
            {
              
                _cardID = value;
                OnPropertyChanged();
            } 
        }

        [Column]
        public int ActionID {  get {return _actionID;}
            set
            {
              
                _actionID = value;
                OnPropertyChanged();
            }
        }


        [Column(DbType = "INT NOT NULL IDENTITY", IsDbGenerated = true, IsPrimaryKey = true)]
        public int CardActionId
        {
            get {return _id;}
            set
            {
              
                _id = value;
                OnPropertyChanged();
            }
        }

        [Association(Storage="_actionRef", ThisKey="ActionID")]
        public DnDAction ActionRef
        {
            get { return _actionRef.Entity; }
            set
            {
                _actionRef.Entity = value;
                ActionID = _actionRef.Entity.Id;
                OnPropertyChanged();
            }
        }


        [Association(Storage = "_cardRef", ThisKey = "CardID")]
        public Card CardRef
        {
            get { return _cardRef.Entity; }
            set
            {
                _cardRef.Entity = value;
                CardID = _cardRef.Entity.Id;
                OnPropertyChanged();
            }
        }

        [Column]
        public bool Local
        {
            get { return _local; }
            set
            {
                _local = value;
                OnPropertyChanged();
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
                handler(this, new PropertyChangedEventArgs(propertyName));
        }

    

    }
}
